package eudjok

class HomeController {


    def index = {
	
		params.max = Math.min(params.max ? params.int('max') : 10, 100)
        [paginaPrincipal:true,
        exemploInstanceList: Exemplo.list(params), exemploInstanceTotal: Exemplo.count(),
		djInstanceList: Dj.findById(session.dj.id),
		djOuvintes: Dj.findById(session.dj.id).ouvintes,
		playList: Musica.findAllByDj(session.dj, [sort:"id", order: "desc"]),
		setListInstanceList: SetList.findAllByDj(session.dj, [max:5, sort:"visitas", order:"desc"]), setListInstanceTotal: SetList.count()]
		
	}
	
	/*Busca musica na playlist*/
	def listBusca = {
		if(params.chave != "null"){
			def musica = Musica.findAllByDjAndTituloIlike(session.dj, "%"+params.chave+"%") 
			render(template:"/common/perfil/homePlaylist", model:[playList:musica])
		}		
	
	}
	
	/*Apaga uma setlist*/
	def deleteSetList = {
        def setListInstance = SetList.get(params.id)
        if (setListInstance != null) {
            
			setListInstance.delete(flush: true)
            flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'setList.label', default: 'SetList'), params.id])}"
			render(template:"/common/perfil/listSetLists", model:[setListInstanceList:SetList.findAllByDj(session.dj, [max:5, sort:"visitas", order:"desc"])])
				
        }
    }
	
	/* Deleta musica da playlist*/
	def deletaMusica = {
		def musicaInstance = Musica.get(params.id)
        if (musicaInstance != null) {
            
                musicaInstance.delete(flush: true)
                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'musica.label', default: 'Musica'), params.id])}"
				render(template:"/common/perfil/homePlaylist", model:[playList: Musica.findAllByDj(session.dj, [sort:"id", order: "desc"])])
			
		}
	}
	/*seleciona musica para ser tocada no player*/
	def escolheMusica = {
		def musica = Musica.get(params.id)
		if (musica != null){
			render(template:"/common/perfil/homeVideo" ,model:[musica:musica])
		}
	}
	
}
